package com.toocms.jinjuhang.utils

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.blankj.utilcode.util.ActivityUtils
import com.toocms.tab.base.BaseActivity

object FragmentUtils {
    fun popTo(fgt: Class<out Fragment?>, isIncludeSelf: Boolean) {
        val fragmentManager =
            (ActivityUtils.getTopActivity() as BaseActivity).supportFragmentManager
        fragmentManager.popBackStack(
            fgt.simpleName,
            if (isIncludeSelf) FragmentManager.POP_BACK_STACK_INCLUSIVE else 0
        )
    }

    fun findFragment(fgt: Class<out Fragment?>) = findFragment(fgt.simpleName)

    fun findFragment(tag: String): Fragment? {
        val fragmentManager =
            (ActivityUtils.getTopActivity() as BaseActivity).supportFragmentManager
        return fragmentManager.findFragmentByTag(tag)
    }
}